home *** CD-ROM | disk | FTP | other *** search
- /* TrackAutoScroll.c */
- /*
- * Copyright © 1989 Martin Minow. All rights reserved.
- *
- * Manage automatic scrolling.
- *
- * void
- * TrackSelView(track_handle)
- * TrackHandle track_handle;
- *
- * If automatic scrolling has been enabled, make sure the
- * start of the selection range is visible, scrolling
- * it into view if necessary. If automatic scrolling
- * is disabled, TrackSelView does nothing.
- *
- * void
- * TrackAutoView(auto, track_handle)
- * Boolean auto;
- * TrackHandle track_handle;
- *
- * Enable or disable automatic scrolling.
- */
- #include "TrackEdit.h"
- #define TR (*tr)
- /*
- * Calculate the width or height of a rect.
- */
- #define width(r) ((r).right - (r).left)
- #define height(r) ((r).bottom - (r).top)
-
- /*
- * Scroll the selection start into view.
- */
- void
- TrackSelView(track_handle)
- TrackHandle track_handle;
- {
- register TrackPtr tr;
- _Track_state state;
- LONGINT hpixel, vpixel;
- LONGINT hdelta, vdelta;
-
- tr = _Track_lock(track_handle, &state);
- if (!_Track_is_set(tr, _Track_do_autoscroll))
- return;
- TrackGetPoint(
- TR.selStart, track_handle, &hpixel, &vpixel);
- vpixel -= TR.lineHeight;
- hdelta = vdelta = 0;
- if (vpixel < (LONGINT) TR.viewRect.top
- || vpixel > (LONGINT) TR.viewRect.bottom)
- vdelta = vpixel - TR.viewRect.top;
- if (hpixel < (LONGINT) TR.viewRect.left
- || hpixel > (LONGINT) TR.viewRect.right)
- hdelta = hpixel - TR.viewRect.left;
- if (hdelta != 0 || vdelta != 0)
- _Track_do_scroll(tr, hdelta, vdelta);
- _Track_unlock(&state);
- }
-
- /*
- * Turn on/off automatic scrolling.
- */
- void
- TrackAutoView(enable, track_handle)
- Boolean enable;
- TrackHandle track_handle;
- {
- if (enable)
- _Track_set((*track_handle), _Track_do_autoscroll);
- else {
- _Track_clear((*track_handle), _Track_do_autoscroll);
- }
- }
-
- /*
- * _Track_autoscroll()
- * Make sure the mouse is within the viewRect, scrolling
- * the text if necessary. This should "pin" the text
- * so it doesn't scroll out of the window.
- */
- void
- _Track_autoscroll(tr, mousep)
- register TrackPtr tr;
- register Point *mousep;
- {
- LONGINT deltah, deltav;
- LONGINT max_horiz, max_vert;
-
- if (!_Track_is_set(tr, _Track_do_autoscroll))
- return;
- deltah = 0;
- deltav = 0;
- if (mousep->v < TR.viewRect.top
- && TR.topPixel > 0) {
- --deltav;
- mousep->v = TR.viewRect.top;
- }
- else if (mousep->v > TR.viewRect.bottom) {
- max_vert = (TR.nLines * TR.lineHeight)
- - height(TR.viewRect);
- if (TR.topPixel < max_vert) {
- ++deltav;
- mousep->v = TR.viewRect.bottom;
- }
- }
- if (mousep->h < TR.viewRect.left
- && TR.leftPixel > 0) {
- --deltah;
- mousep->h = TR.viewRect.left;
- }
- else if (mousep->h > TR.viewRect.right) {
- max_horiz = TR.lineWidth - width(TR.viewRect);
- if (TR.crOnly < 0 || TR.leftPixel < max_horiz) {
- ++deltah;
- mousep->h = TR.viewRect.right;
- }
- }
- /*
- * Each pass through autoscroll moves the window
- * a few pixels at a time -- this slows things down
- * so the user can stop before the text disappears.
- */
- if (deltav != 0 || deltah != 0) {
- _Track_do_scroll(
- tr,
- deltah * TR.lineHeight,
- deltav * TR.lineHeight
- );
- }
- }
-